from  time import sleep
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from lxml import etree
# 实现无可视化界面
# from selenium.webdriver.chrome.options import Options
# 实现规避检测
from selenium.webdriver import ChromeOptions

# 无可视化界面操作
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
# 实现规避检测
options.add_experimental_option('excludeSwitches', ['enable-automation'])

service = Service()
service.path = r'chromedriver.exe'
# 启动浏览器
# 如何实现让selenium规避被检测到的风险
browser = webdriver.Chrome(service=service,options = options)

# 无可视化界面(无头浏览器) phantomJs
browser.get('https://www.baidu.com/')

print(browser.page_source)


sleep(2)
browser.quit()